package com.nanhai.buddhist.college.module.collegebase.dal.mysql.textbookinfo;

import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.mybatis.core.mapper.BaseMapperX;
import com.nanhai.buddhist.college.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.textbookinfo.info.vo.TextbookInfoExportReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.textbookinfo.info.vo.TextbookInfoPageReqVO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.textbookinfo.TextbookInfoDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.textbooktype.TextbookTypeDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 教材列表 Mapper
 *
 * @author AKai
 */
@Mapper
public interface TextbookInfoMapper extends BaseMapperX<TextbookInfoDO> {

    default PageResult<TextbookInfoDO> selectPage(TextbookInfoPageReqVO reqVO) {
        return selectPageForJoin(reqVO, TextbookInfoDO.class, new MPJLambdaWrapperX<TextbookInfoDO>()
                .likeIfPresent(TextbookInfoDO::getTextbookName, reqVO.getTextbookName())
                .likeIfPresent(TextbookTypeDO::getTypeName, reqVO.getTypeName())
                .leftJoin(TextbookTypeDO.class, TextbookTypeDO::getId, TextbookInfoDO::getTypeId)
                .selectAll(TextbookInfoDO.class)
                .selectAs(TextbookTypeDO::getTypeName,TextbookInfoDO::getTypeName)
                .orderByDesc(TextbookInfoDO::getCreateTime));
    }

    default List<TextbookInfoDO> selectList(TextbookInfoExportReqVO reqVO) {
        return selectJoinList(TextbookInfoDO.class,new MPJLambdaWrapperX<TextbookInfoDO>()
                .likeIfPresent(TextbookInfoDO::getTextbookName, reqVO.getTextbookName())
                .likeIfPresent(TextbookTypeDO::getTypeName, reqVO.getTypeName())
                .leftJoin(TextbookTypeDO.class, TextbookTypeDO::getId, TextbookInfoDO::getTypeId)
                .selectAll(TextbookInfoDO.class)
                .selectAs(TextbookTypeDO::getTypeName,TextbookInfoDO::getTypeName)
                .orderByDesc(TextbookInfoDO::getCreateTime));
    }

}
